package com.java.test.user.mapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.user.dto.UserInfo;

@Component
public class UserMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<UserInfo> getAllUser(String name) {
		String sql = "select * from t_user_info where user_name=?";
		List<UserInfo> list = jdbcTemplate.query(sql, new UserInfo(), name);
		return list;
	}

	public UserInfo selectUserBynamePassword(String name, String passWrod) {
		String sql = "select * from t_user_info where user_name=? and password=?";
		UserInfo info = null;
		try {
			info = jdbcTemplate.queryForObject(sql, new UserInfo(), name, passWrod);
		} catch (DataAccessException e) {
			return null;
		}
		return info;
	}

}
